package com.winhxd.b2c.order.controller;

import com.winhxd.b2c.common.constant.BusinessCode;
import com.winhxd.b2c.common.domain.ResponseResult;
import com.winhxd.b2c.common.domain.order.condition.OrderSalesSummaryCondition;
import com.winhxd.b2c.common.domain.order.condition.OrderSummaryCondition;
import com.winhxd.b2c.common.domain.order.condition.OrderUsersCondition;
import com.winhxd.b2c.common.domain.order.vo.OrderBusinessSummaryVO;
import com.winhxd.b2c.common.domain.order.vo.OrderUserBaseSummaryVO;
import com.winhxd.b2c.common.domain.order.vo.OrderUsersProfitListVO;
import com.winhxd.b2c.common.exception.BusinessException;
import com.winhxd.b2c.common.feign.order.OrderDataStatisticsServiceClient;
import com.winhxd.b2c.common.util.JsonUtil;
import com.winhxd.b2c.order.service.OrderDataStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author lijianhua
 * @Description //订单数据统计
 * @Date 14:33 2019/1/7
 **/
@Api(tags = "OrderDataStatistics")
@RestController
public class OrderDataStatisticsController implements OrderDataStatisticsServiceClient {
    private static final Logger LOGGER = LoggerFactory.getLogger(OrderDataStatisticsController.class);
    @Autowired
    private OrderDataStatisticsService orderDataStatisticsService;

    @Override
    @ApiOperation(value = "后台运营数据查询", response = OrderBusinessSummaryVO.class, notes = "后台运营数据查询")
    public ResponseResult<OrderBusinessSummaryVO> getBusinessSummarySummary(@RequestBody OrderSalesSummaryCondition condition) {
        String logTitle = "/order/4701/v1/getBusinessSummarySummary-后台运营数据查询";
        LOGGER.info("{}=--开始--{}", logTitle, JsonUtil.toJSONString(condition));
        ResponseResult<OrderBusinessSummaryVO> result = new ResponseResult<>();

        OrderBusinessSummaryVO vo = orderDataStatisticsService.getBusinessSummarySummary(condition);
        result.setData(vo);

        LOGGER.info("{}=--结束 result={}", logTitle, result);
        return result;
    }

    @Override
    @ApiOperation(value = "用户收益查询", response = OrderUsersProfitListVO.class, notes = "用户收益查询")
    public ResponseResult<List<OrderUsersProfitListVO>> findOrderUsersProfitList(@RequestBody OrderUsersCondition condition) {
        String logTitle = "/order/4702/v1/findOrderUsersProfitList-用户收益查询";
        LOGGER.info("{}=--开始--{}", logTitle, JsonUtil.toJSONString(condition));
        if (condition == null || condition.getCustomerIds() == null) {
            throw new BusinessException(BusinessCode.CODE_1026);
        }
        ResponseResult<List<OrderUsersProfitListVO>> result = new ResponseResult<>();

        List<OrderUsersProfitListVO> list = orderDataStatisticsService.findOrderUsersProfitList(condition);
        result.setData(list);

        LOGGER.info("{}=--结束 result={}", logTitle, result);
        return result;
    }

    @Override
    @ApiOperation(value = "用户信息查询", response = OrderUsersProfitListVO.class, notes = "用户信息查询")
    public ResponseResult<OrderUserBaseSummaryVO> getUserBaseSummarySummary(@RequestBody OrderSummaryCondition condition) {
        ResponseResult<OrderUserBaseSummaryVO> result= new ResponseResult<>();
        OrderUserBaseSummaryVO vo=orderDataStatisticsService.getUserBaseSummarySummary(condition);
        result.setData(vo);
        return result;
    }
}
